﻿package core.ui.options
{
    import core.event.*;
    import core.ui.controls.*;
    import core.ui.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;

    public class ShadowOptions extends Sprite
    {
        var ed:Tuyitu;
        var filter:DropShadowFilter;
        public var opacity:Slidebar;
        public var distance:Slidebar;
        public var size:Slidebar;
        public var angle:DegreeSelector;
        public var color:ColorPad;

        public function ShadowOptions(param1:Tuyitu, param2:DropShadowFilter)
        {
            this.ed = param1;
            this.filter = param2;
            this.opacity = new Slidebar("rm_opacity", 0, 100, 100, Math.round(param2.alpha * 100), true);
            this.opacity.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.opacity.x = 80;
            this.opacity.y = 0;
            addChild(this.opacity);
            this.distance = new Slidebar("rm_distance", 0, 100, 100, param2.distance, true);
            this.distance.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.distance.x = 80;
            this.distance.y = 25;
            addChild(this.distance);
            this.size = new Slidebar("rm_size", 0, 100, 100, param2.blurX, true);
            this.size.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.size.x = 80;
            this.size.y = 50;
            addChild(this.size);
            this.angle = new DegreeSelector("rm_angle", param2.angle - 180);
            this.angle.addEventListener(SliderEvent.DRAG, this.ValueChange, false, 1, true);
            this.angle.x = 80;
            this.angle.y = 85;
            addChild(this.angle);
            this.color = new ColorPad(param2.color, true);
            this.color.addEventListener(MouseEvent.MOUSE_DOWN, this.ColorMouseDown, false, 1, true);
            this.color.addEventListener(ColorPadEvent.CHOOSE_COLOR, this.ColorChange, false, 1, true);
            this.color.x = 80;
            this.color.y = 125;
            addChild(this.color);
            var _loc_3:* = new Literal("rm_color");
            _loc_3.x = 80 - _loc_3.width - 2;
            _loc_3.y = 125;
            addChild(_loc_3);
            return;
        }// end function

        public function ColorMouseDown(event:MouseEvent) : void
        {
            new ColorPicker(this.ed, event.target as ColorPad);
            return;
        }// end function

        public function ColorChange(event:ColorPadEvent) : void
        {
            this.filter.color = event.color;
            dispatchEvent(new ChangeEvent("update"));
            return;
        }// end function

        public function ValueChange(... args) : void
        {
            this.filter.alpha = this.opacity.value / 100;
            this.filter.distance = this.distance.value;
            args = this.size.value;
            this.filter.blurY = args;
            this.filter.blurX = args;
            this.filter.angle = this.angle.value + 180;
            dispatchEvent(new ChangeEvent("update"));
            return;
        }// end function

    }
}
